#pragma once
#include <Windows.h>
#include <time.h>
#include <vector>
#include <queue>
#include <detours.h>
#include "../ConfigFile.h"
#include "../Utils.h"
#include "../DBAccess.h"
#include "../XenMemory/XenMemory.h"

typedef int (__thiscall* DecryptCall)(void* pthis, unsigned char* buffer, int length);
typedef int (__thiscall* EncryptCall)(void* pthis, unsigned char* buffer, int length);


struct ITEM {
	int id;
	std::string name;
	int x;
	int y;
};

class PacketHandler
{
private:
	static byte offsets[];
	
	static std::queue<std::vector<unsigned char>> packets;
	static bool packetLock;
	static std::vector<unsigned char> packet;

	static DecryptCall decryptDefault;
	static EncryptCall encrypt;

	int ListenEvent(unsigned char* buffer, int len);
	int ListenEventa(unsigned char* buffer, int len);

public:
	static bool attached;
	static std::vector<ITEM> items;
	static bool itemsLock;
	static bool itemSniffer;

	static void Attach();
	static void Detach();
	PacketHandler();
	int DetourEncrypt(byte *packet, size_t len);
	int DetourDecrypt(byte *packet, size_t len);
	static void MyEncrypt(byte *packet, size_t len);
	static void MyDecrypt(byte *packet, size_t len);
	static void ProcessPacket(byte *packet, int length);
	static void ProcessPacket();
};

